﻿using _RobotInspection.DTO;
using _RobotInspection.Entities;
using _RobotInspection.Interfaces;
using _RobotInspection.Models;
using Microsoft.AspNetCore.Mvc;

namespace _RobotInspection.Controllers
{
    /// <summary>
    /// 点检项目相关控制层
    /// </summary>
    [ApiController]
    [Route("[controller]/[action]")]
    public class InspectionItemController : ControllerBase
    {
        private readonly IInspectionItemService _service;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="service"></param>
        public InspectionItemController(IInspectionItemService service)
        {
            _service = service;
        }

        /// <summary>
        /// 根据设备Id查询点检项目
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public async Task<ActionResult<ApiResponse<List<inspection_items>>>> GetItemsByEquipmentId([FromRoute] long id)
        {
            var result = await _service.GetItemsByEquipmentIdAsync(id);
            return new OkObjectResult(result);
        }

        /// <summary>
        /// 创建点检项目
        /// </summary>
        /// <param name="queryDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult<ApiResponse<inspection_items>>> InsertItem([FromQuery] InspectionItemInsertDto queryDto)
        {
            var result = await _service.InsertItemAsync(queryDto);
            return new OkObjectResult(result);
        }

        /// <summary>
        /// 修改点检项目
        /// </summary>
        /// <param name="queryDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ActionResult<ApiResponse<inspection_items>>> UpdateItem([FromQuery] InspectionItemUpdateDto queryDto)
        {
            var result = await _service.UpdateItemAsync(queryDto);
            return new OkObjectResult(result);
        }

        /// <summary>
        /// 根据点检项目id删除点检项目
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public async Task<ActionResult<ApiResponse<inspection_items?>>> DeleteItem([FromRoute]  long id)
        {
            var result = await _service.DeleteItemAsync(id);
            return new OkObjectResult(result);
        }

        /// <summary>
        /// 批量删除点检项目
        /// </summary>
        /// <param name="idList"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ActionResult<ApiResponse<List<string>>>> DeleteItemList([FromQuery] List<long> idList)
        {
            var result = await _service.DeleteItemListAsync(idList);
            return new OkObjectResult(result);
        }
    }
}
